package lg.minecraft.plugin.pokedex.config;

import lg.minecraft.plugin.library.config.LGBaseConfig;
import lg.minecraft.plugin.pokedex.LGPokedex;
import lg.minecraft.plugin.pokedex.storage.StorageType;
import lombok.Getter;

import java.io.File;
import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class MainConfig extends LGBaseConfig {

    public static final MainConfig INSTANCE = new MainConfig();

    private StorageType storageType;
    private int maxStorageCount;
    private File ymlStoragePath;
    private String mySqlStorageUrl;
    private String mySqlUser;
    private String mySqlPassword;

    public MainConfig() {
        super(LGPokedex.getInstance(), "config");
        init();
    }

    @Override
    public void load() {
        super.load();

        String typeString = getString("storage.type", "YAML");
        storageType = StorageType.getStorageType(typeString);
        maxStorageCount = getInt("storage.max_count", 100);
        String ymlPath = getString("storage.yml.path", "plugins\\LGPokedex\\playerData");
        ymlStoragePath = new File(ymlPath);
        if (!ymlStoragePath.exists()) {
            if (!ymlStoragePath.mkdirs()) {
                LGPokedex.getInstance().severe("Failed to create storage path.");
            }
        }

        mySqlStorageUrl = getString("storage.mysql.url");
        mySqlUser = getString("storage.mysql.user");
        mySqlPassword = getString("storage.mysql.password");
    }

}
